class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left=0;
        int right=0;
        int maxlenth=0;
        int lenth=0;
        while(right<nums.size())
        {
            if(nums[right]==0)
            {
                if(k==0)
                {
                    while(nums[left]==1)
                        left++;
                    left++;
                    k++;
                }
                k--;
            }
            lenth=right-left+1;
            maxlenth=maxlenth>lenth?maxlenth:lenth;
            right++;
        }
        return maxlenth;
    }
};